package com.hex.ds.em.hcdp.gauss.analyze.script.performance.entity;

import cn.hutool.core.util.StrUtil;
import com.hex.ds.em.hcdp.basic.common.MarkMsg;
import java.util.HashMap;
import java.util.Map;

/**
 * @Package com.hex.ds.em.hcdp.gauss.analyze.script.performance.entity
 * @ClassName CheckTableUsageCountEntity
 * @Description 规则信息实体类-原表使用次数
 * @Author gj.xu
 * @Date 2024/9/23 10:39
 * @Version v2.0
 **/
public class CheckTableUsageCountEntity extends MarkMsg {

  public Map<String, String> tables = new HashMap<>();
  public Map<String, Integer> tablesUsageCount = new HashMap<>();
  private String ruleMark = "/* [GEN-PERF-020] [性能] 原表使用次数 - 表名：{}，次数：{} */";

  @Override
  protected String ruleMark() {
    return String.join("\n", tables.values());
  }

  public String addRuleMark(String tableName) {
    //更新使用次数
    if (tablesUsageCount.containsKey(tableName)) {
      tablesUsageCount.put(tableName, tablesUsageCount.get(tableName) + 1);
    } else {
      tablesUsageCount.put(tableName, 1);
    }
    return tables
        .put(tableName, StrUtil.format(ruleMark, tableName, tablesUsageCount.get(tableName)));
  }

}
